import json

units = {
    "DvpUnit": [
        {
            "DvpUnit_Name": "王氏公司",
            "DvpUnit_ID": "08",
            "DvpUnit_Rank": "1",
            "children": [
                {
                    "DvpUnit_ID": "09",
                    "DvpUnit_Name": "王氏-北方分公司",
                    "DvpUnit_Rank": "2",
                    "children": [
                        {
                            "DvpUnit_ID": "13",
                            "DvpUnit_Name": "王氏-北方-采油一厂",
                            "DvpUnit_Rank": "3"
                        },
                        {
                            "DvpUnit_ID": "14",
                            "DvpUnit_Name": "王氏-北方-采油二厂",
                            "DvpUnit_Rank": "3"
                        }
                    ]
                },
                {
                    "DvpUnit_ID": "10",
                    "DvpUnit_Name": "王氏-南方分公司",
                    "DvpUnit_Rank": "2",
                    "children": [
                        {
                            "DvpUnit_ID": "11",
                            "DvpUnit_Name": "王氏-南方-采油一厂",
                            "DvpUnit_Rank": "3",
                            "children": [
                                {
                                    "DvpUnit_ID": "15",
                                    "DvpUnit_Name": "王氏-南方-一厂-机关",
                                    "DvpUnit_Rank": "4"
                                },
                                {
                                    "DvpUnit_ID": "16",
                                    "DvpUnit_Name": "王氏-南方-一厂-生产科",
                                    "DvpUnit_Rank": "4"
                                },
                                {
                                    "DvpUnit_ID": "17",
                                    "DvpUnit_Name": "王氏-南方-一厂-技术科",
                                    "DvpUnit_Rank": "4"
                                }
                            ]
                        },
                        {
                            "DvpUnit_ID": "12",
                            "DvpUnit_Name": "王氏-南方-采油二厂",
                            "DvpUnit_Rank": "3"
                        }
                    ]
                }
            ]
        },
        {
            "DvpUnit_Name": "赵氏公司",
            "DvpUnit_ID": "18",
            "DvpUnit_Rank": "1",
            "children": [
                {
                    "DvpUnit_ID": "19",
                    "DvpUnit_Name": "赵氏-东方分公司",
                    "DvpUnit_Rank": "2",
                    "children": [
                        {
                            "DvpUnit_ID": "21",
                            "DvpUnit_Name": "赵氏-东方-采油一厂",
                            "DvpUnit_Rank": "3",
                            "children": [
                                {
                                    "DvpUnit_ID": "25",
                                    "DvpUnit_Name": "赵氏-西方-一厂-机关",
                                    "DvpUnit_Rank": "4"
                                },
                                {
                                    "DvpUnit_ID": "26",
                                    "DvpUnit_Name": "赵氏-西方-一厂-生产科",
                                    "DvpUnit_Rank": "4"
                                },
                                {
                                    "DvpUnit_ID": "27",
                                    "DvpUnit_Name": "赵氏-西方-一厂-技术科",
                                    "DvpUnit_Rank": "4"
                                }
                            ]
                        },
                        {
                            "DvpUnit_ID": "22",
                            "DvpUnit_Name": "赵氏-东方-采油二厂",
                            "DvpUnit_Rank": "3"
                        }
                    ]
                },
                {
                    "DvpUnit_ID": "20",
                    "DvpUnit_Name": "赵氏-西方分公司",
                    "DvpUnit_Rank": "2",
                    "children": [
                        {
                            "DvpUnit_ID": "23",
                            "DvpUnit_Name": "赵氏-西方-采油一厂",
                            "DvpUnit_Rank": "3"
                        },
                        {
                            "DvpUnit_ID": "24",
                            "DvpUnit_Name": "赵氏-西方-采油二厂",
                            "DvpUnit_Rank": "3"
                        }
                    ]
                }
            ]
        }
    ],
}

dvp_unit = units['DvpUnit']
# children_list = list()
# remove_count = 0
# for i in range(len(dvp_unit)):
#     i = i - remove_count
#     name = dvp_unit[i]['DvpUnit_Name']
#     if name in ['王氏公司', ]:
#         children = dvp_unit[i]['children']
#         children_list.extend(children)
#         del dvp_unit[i-remove_count]
#         remove_count = remove_count + 1
# dvp_unit.extend(children_list)

def do_something():
    children_list = list()
    remove_count = 0
    for i in range(len(dvp_unit)):
        i = i - remove_count
        name = dvp_unit[i]['DvpUnit_Name']
        if name in ['王氏公司', ]:
            children = dvp_unit[i]['children']
            children_list.extend(children)
            del dvp_unit[i - remove_count]

            remove_count = remove_count + 1
    dvp_unit.extend(children_list)

print(dvp_unit)
